<?php

namespace App\Admin\Controllers\shop;

use \App\Models\shop\Shop;
use App\Services\shop\CityService;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ShopController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '门店列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Shop);
        $grid->model()->orderByDesc('id');
        $grid->column('id', __('Id'));
        $grid->column('img', __('Img'))->lightbox(['width' => 50, 'height' => 50, 'class' => ['circle', 'thumbnail']]);;
        $grid->column('name', __('Name'));
        $grid->column('address', __('Address'));
//        $grid->column('log', __('Log'));
//        $grid->column('lat', __('Lat'));
        $grid->column('phone', __('Phone'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Shop::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('img', __('Img'));
        $show->field('name', __('Name'));
        $show->field('address', __('Address'));
        $show->field('log', __('Log'));
        $show->field('lat', __('Lat'));
        $show->field('selling_num', __('Selling num'));
        $show->field('start_hour', __('Start hour'));
        $show->field('end_hour', __('End hour'));
        $show->field('phone', __('Phone'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Shop);

        $form->image('img', __('Img'))->rules('required');
        $form->text('name', __('Name'))->rules('required');
        $form->text('address', __('Address'))->rules('required');
        $form->mobile('phone', __('Phone'))->rules('required');

        $form->distpicker([
            'province_id' => '省',
            'city_id'     => '市',
            'district_id' => '区'
        ]);
        $form->latlong('lat', 'lng', 'Position');

        return $form;
    }
}
